#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int t,f;
long long n,m,l,v1,x,y,s,qmin,qh1,qmax,qh2,pmax;
long long d[N],v[N],a[N],p[N];//,vis[N],zt[N];//v: c1 w0 
struct car{
	//int jk[N];
	long long q;//,z,bh;
}cs[N];
//void iscs(int d0,int v0,int a0,int de){
	//if(a0>0)
	//{
		//if(sqrt(2*a0*(l-d0)+v0*v0)>v1)
		//{
			//s++;
			//vis[s]=1;
			//cs[s].q=l-(v1*v1-v0*v0)/2/a0;//bu
			//if(cs[s].q<qmin)
				//qmin=cs[s].q;
			//if(cs[s].q>qmax)
				//qmax=cs[s].q;
			//cs[s].bh=de;
			//cs[s].z=l;//han
			//vis[s]=3;
		//}
	//}
	//if(v0>v1)
	//{
		//s++;
		//cs[s].bh=de;
		//cs[s].q=d[de];//han
		//if(cs[s].q<=qmin)
				//qmin=cs[s].q,qh1=1;
		//if(cs[s].q>qmax)
				//qmax=cs[s].q,qh2=1;
		//if(a0<0)
		//{
			//vis[s]=2;
			//cs[s].z=d0+(v1*v1-v0*v0)/(2*a0);//bu
		//}
		//else
		//{
			//cs[s].z=l;//han
			//vis[s]=1;
		//}
	//}
	//return ;
//}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		memset(d,0,sizeof(d));
		memset(v,0,sizeof(v));
		memset(a,0,sizeof(a));
		memset(p,0,sizeof(p));
		memset(cs,0,sizeof(cs));
		x=0;y=0;s=0;
		scanf(" %lld %lld %lld %lld",&n,&m,&l,&v1);
		for(long long i=1;i<=n;i++)
		{
			scanf(" %lld %lld %lld",&d[i],&v[i],&a[i]);
			//iscs(d[i],v[i],a[i],i);
			if(v[i]>v1)
			{
				s++;
				//cs[s].bh=i;
				cs[s].q=d[i];//han
				if(cs[s].q<=qmin)
						qmin=cs[s].q,qh1=1;
				if(cs[s].q>qmax)
						qmax=cs[s].q,qh2=1;
				//if(a[i]<0)
				//{
					//vis[s]=2;
					//cs[s].z=d[i]+(v1*v1-v[i]*v[i])/(2*a[i]);//bu
				//}
				//else
				//{
					//cs[s].z=l;//han
					//vis[s]=1;
				//}
			}
			if(a[i])
				f=1;
		}
		
		for(long long i=1;i<=m;i++)
		{
			scanf(" %lld",&p[i]);
			if(pmax<p[i])
				pmax=p[i];
			//for(int j=1;j<=s;j++)
			//{
				//if(vis[j]==1&&p>=cs[j].q&&p<=cs[j].z)
				//{
					//x++;
				//}
				//if(vis[j]==2&&p>=cs[j].q&&p<cs[j].z)
				//{
					//x++;
				//}
				//if(vis[j]==3&&p>cs[j].q&&p<=cs[j].z)
				//{
					//x++;
				//}
			//}
		}
		if(f==0)
		{
			
			if(qh2==1&&qmax<pmax)
			{
				cout<<s<<" "<<m-1<<"\n";
				continue;
			}
			if(qh2==0&&qmax<=pmax)
			{
				cout<<s<<" "<<m-1<<"\n";
				continue;
			}
			if(qh1==1&&qh2==1&&pmax>=qmin&&pmax<=qmax)
			{
				for(long long i=1;i<=s;i++)
				{
					if(cs[i].q>pmax)
						s--;
				}	
				cout<<s<<" "<<m-1<<"\n";
				continue;
			}
			if(qh1==1&&qh2==0&&pmax>=qmin&&pmax<qmax)
			{
				for(long long i=1;i<=s;i++)
				{
					if(cs[i].q>pmax)
						s--;
				}	
				cout<<s<<" "<<m-1<<"\n";
				continue;
			}
			if(qh1==0&&qh2==1&&pmax>qmin&&pmax<=qmax)
			{
				for(long long i=1;i<=s;i++)
				{
					if(cs[i].q>pmax)
						s--;
				}	
				cout<<s<<" "<<m-1<<"\n";
				continue;
			}
			if(qh1==0&&qh2==0&&pmax>qmin&&pmax<qmax)
			{
				for(long long i=1;i<=s;i++)
				{
					if(cs[i].q>pmax)
						s--;
				}	
				cout<<s<<" "<<m-1<<"\n";
				continue;
			}
			if(qh1==0&&pmax<=qmin)
			{
				cout<<"0 "<<m<<"\n";
				continue;}
			if(qh1==1&&pmax<qmin){
				cout<<"0 "<<m<<"\n";
				continue;}
		}
		
		printf("%lld %lld\n",x,y);
	}
	return 0;
}
